package com.whh.common;

import com.whh.zuowen.service.ZuowenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Controller
public class BaseController {
    @Autowired
    public ZuowenService zuowenService;


    @ModelAttribute
    public void addAttributes(Model model) {
        model.addAttribute("hot", zuowenService.getHot());
        //随机10个，作为推荐id
        List<Integer> ids = new ArrayList<>(10);
        int max=3000,min=3;
        for(int i = 0; i < 10; i++) {
            int id = (int) (Math.random() * (max - min) + min);
            ids.add(id);
        }
        model.addAttribute("tuijianList", zuowenService.getTuijian(ids));
    }


}
